// pages/driver/car_list/car_list.js
Page({
  data:{
    IDD: '',
    list: [],
    loadError: false,
    noMoreData: false
  },
  onLoad:function(options){
      // 页面初始化 options为页面跳转所带来的参数
      var IDD1 = options.IDD;
      this.setData({
          IDD: IDD1
      });

      getServiceData(this,1);
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },

  bindRetry:function(){
    getServiceData(this,1);
  },

  //下拉加载
  onPullDownRefresh: function(){
      getServiceData(this,1);

      //下拉动作完成之后，将index置为1，没有更多数据字段变为false
      this.data.pageIndex = 1;
      this.data.noMoreData = false;
  },
})

function getServiceData(that,pageIndex){
    wx.showToast({
        title: '正在加载...',
        icon: 'loading',
        duration: 10000
    });

    if(pageIndex == 1){
        that.setData({
            list: []
        });
    }

    var userInfo = wx.getStorageSync('userInfo');
    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/OrderDriversGuiderList.ashx',
      data: {
          IDD: that.data.IDD,
          stype: '3',
          PageIndex: pageIndex,
          PageSize: 20,
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
          // success
          console.log(res);
          var code = res.data.code;
          if(code == 0){
              if(res.data.data.length > 0){
                  console.log('yes');
                  that.setData({
                      list: that.data.list.concat(res.data.data),
                      noMoreData: false
                  });
              }else{
                  that.setData({
                      noMoreData: true
                  });
              }
          }else{
              that.setData({
                  loadError: true
              });
          }
      },
      fail: function() {
          // fail
          that.setData({
              loadError: true
          });
      },
      complete: function() {
          // complete
          wx.hideToast();
          wx.stopPullDownRefresh();
      }
    })
}